/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

var app = __webpack_require__(1);
var loginCtrl = __webpack_require__(2)(app);
var FormCtrl = __webpack_require__(3)(app);

/***/ }),
/* 1 */
/***/ (function(module, exports) {

var app = angular.module('myApp', ['ngRoute', 'ui.bootstrap', 'angularFileUpload']);
app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: 'login.html',
        controller: 'loginCtrl'
    }).when('/register', {
        templateUrl: 'register.html',
        controller: 'FormCtrl'
    }).otherwise({
        redirectTo: '/login'
    });
}]);

module.exports = app;

/***/ }),
/* 2 */
/***/ (function(module, exports) {

module.exports = function (app) {
    app.controller('loginCtrl', function ($scope, $http, $location) {
        $scope.loginData = {
            name: '',
            password: '',
            err_msg: ''
        };
        $scope.login = function () {

            $http({
                method: 'POST',
                url: 'api/merchant/login',
                data: $scope.loginData
            }).then(function successCallback(response) {
                console.log(response);
                if (response.data.status == true) {
                    alert('登录成功');
                    window.location.href = 'manager.html';
                } else {
                    console.log(response);
                    err_msg = response.data.message;
                    alert(err_msg);
                }
            }, function errorCallback(response) {
                alert("异常");
            });
        };

        $scope.test = function () {
            // $location.path('https://www.baidu.com');
            window.location.href = 'manager.html';
        };
    });
};

/***/ }),
/* 3 */
/***/ (function(module, exports) {

module.exports = function (app) {
    app.controller('FormCtrl', ['$scope', 'FileUploader', '$http', '$location', function ($scope, FileUploader, $http, $location) {

        $scope.headHide = true;
        $scope.idcardHide = true;

        $scope.headpicUploader = new FileUploader({
            url: '/api/upload/headpic',
            removeAfterUpload: true,
            queueLimit: 1
        });
        $scope.idcardpicUploader = new FileUploader({
            url: '/api/upload/idcardpic',
            removeAfterUpload: true,
            queueLimit: 1
        });
        $scope.ensurePassword = '';
        $scope.headpic = '';
        $scope.idcardpic = '';
        $scope.formInput = {
            merchantName: '',
            password: '',
            address: '',
            headPic: '',
            idCardPic: ''
        };

        // warnning using DOM
        $scope.headBrowse = function () {
            document.getElementById('headFile').click();
        };

        /* 上传图片 START*/
        // 提交上传
        $scope.headUpload = function () {
            console.log("call upload");
            $scope.headpicUploader.uploadAll();
        };

        // 上传完成执行此方法
        $scope.headpicUploader.onCompleteItem = function (item, response, status, headers) {
            console.log("callback upload", response.path);
            $scope.formInput.headPic = response.path;
            $scope.headHide = false;
            alert("上传成功");
        };
        /* 上传图片 END*/

        // warnning using DOM
        $scope.idcardBrowse = function () {
            document.getElementById('idcardFile').click();
        };

        /* 上传图片 START*/
        // 提交上传
        $scope.idcardUpload = function () {
            console.log("call upload");
            $scope.idcardpicUploader.uploadAll();
        };

        // 上传完成执行此方法
        $scope.idcardpicUploader.onCompleteItem = function (item, response, status, headers) {
            console.log("callback upload", response.path);
            $scope.formInput.idCardPic = response.path;
            $scope.idcardHide = false;
            alert("上传成功");
        };
        /* 上传图片 END*/

        // 提交申请
        $scope.submitForm = function () {
            if ($scope.validateCompletion()) {
                $http.post('/api/merchant/register', $scope.formInput).then(function (response) {
                    console.log(response.data);
                    alert("注册成功");
                    $location.path('index.html');
                }, function (response) {
                    alert('Register fail..');
                });
            }
        };

        // // Step 1
        // $scope.headpicUploader.onCompleteItem = function (item, response, status, headers) {
        //     console.log(response.path);
        //     $scope.formInput.headPic = response.path;
        //     $scope.idcardpicUploader.uploadAll();
        // }
        // // Step 2
        // $scope.idcardpicUploader.onCompleteItem = function (item, response, status, headers) {
        //     console.log(response.path);
        //     $scope.formInput.idCardPic = response.path;
        //     $http.post('/api/merchant/register', $scope.formInput).then(
        //         function (response) {
        //             console.log(response.data);
        //         },
        //         function (response) {
        //             alert('Register fail..');
        //         }
        //     );
        // }
        // // Step 0
        // $scope.submitForm = function () {
        //     // if ($scope.headpic && $scope.idcardpic) {
        //         $scope.headpicUploader.uploadAll();
        //     // } else {
        //         // alert('Please select the pic files..');
        //     // }
        // }

        // 前端校验
        $scope.validate = {
            class: {
                success: 'has-success has-feedback',
                warnning: 'has-warning has-feedback',
                error: 'has-error has-feedback',
                successGlyphicon: 'glyphicon glyphicon-ok form-control-feedback',
                warningGlyphicon: 'glyphicon glyphicon-warning-sign form-control-feedback',
                errorGlyphicon: 'glyphicon glyphicon-remove form-control-feedback'
            },
            div: {},
            span: {},
            help: {}
        };

        $scope.validateCompletion = function () {
            var validate = true;
            if ($scope.formInput.merchantName == undefined || $scope.formInput.merchantName == '') {
                $scope.validate.div.merchantName = $scope.validate.class.error;
                $scope.validate.span.merchantName = $scope.validate.class.errorGlyphicon;
                $scope.validate.help.merchantName = '用户名不能为空';
                validate = false;
            }
            return validate;
        };

        $scope.merchantNameChange = function () {
            var length = $scope.formInput.merchantName.length;
            if ($scope.formInput.merchantName == undefined || $scope.formInput.merchantName == '' || length == 0) {
                $scope.validate.div.merchantName = '';
                $scope.validate.span.merchantName = '';
                $scope.validate.help.merchantName = '';
            } else if (length < 20) {
                $scope.validate.div.merchantName = $scope.validate.class.success;
                $scope.validate.span.merchantName = $scope.validate.class.successGlyphicon;
                $scope.validate.help.merchantName = '';
            } else {
                $scope.validate.div.merchantName = $scope.validate.class.error;
                $scope.validate.span.merchantName = $scope.validate.class.errorGlyphicon;
                $scope.validate.help.merchantName = '用户名长度不能超过20位';
            }
        };

        $scope.passwordChange = function () {
            var length = $scope.formInput.password.length;
            if (length == 0) {
                $scope.validate.div.password = '';
                $scope.validate.span.password = '';
                $scope.validate.help.password = '';
            } else if (length < 10) {
                $scope.validate.div.password = $scope.validate.class.warnning;
                $scope.validate.span.password = $scope.validate.class.warningGlyphicon;
                $scope.validate.help.password = '建议密码长度大于10位';
            } else if (length < 20) {
                $scope.validate.div.password = $scope.validate.class.success;
                $scope.validate.span.password = $scope.validate.class.successGlyphicon;
                $scope.validate.help.password = '';
            } else {
                $scope.validate.div.password = $scope.validate.class.error;
                $scope.validate.span.password = $scope.validate.class.errorGlyphicon;
                $scope.validate.help.password = '密码长度不能超过20位';
            }
        };

        $scope.ensurePasswordChange = function () {
            if ($scope.ensurePassword.length == 0) {
                $scope.validate.div.ensurePassword = '';
                $scope.validate.span.ensurePassword = '';
                $scope.validate.help.ensurePassword = '';
            } else if ($scope.formInput.password != $scope.ensurePassword) {
                $scope.validate.div.ensurePassword = $scope.validate.class.error;
                $scope.validate.span.ensurePassword = $scope.validate.class.errorGlyphicon;
                $scope.validate.help.ensurePassword = '两次密码不一致';
            } else {
                $scope.validate.div.ensurePassword = $scope.validate.class.success;
                $scope.validate.span.ensurePassword = $scope.validate.class.successGlyphicon;
                $scope.validate.help.ensurePassword = '';
            }
        };

        $scope.addressChange = function () {
            if ($scope.formInput.address.length == 0) {
                $scope.validate.div.address = '';
                $scope.validate.span.address = '';
                $scope.validate.help.address = '';
            } else {
                $scope.validate.div.address = $scope.validate.class.success;
                $scope.validate.span.address = $scope.validate.class.successGlyphicon;
                $scope.validate.help.address = '';
            }
        };
    }]);
};

/***/ })
/******/ ]);